package com.atiguigu.spring6.validator.two;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class MyValidation1 {

    @Autowired
    private Validator validator;

    public boolean validatorByUser(User user) {
        Set<ConstraintViolation<User>> validate = validator.validate(user);
        for (ConstraintViolation<User> constraintViolation : validate) {
            System.out.println(constraintViolation.getMessage());
        }
        return validate.size() == 0;
    }
}
